//
//  HTTPPlugin.h
//  Pure Dates
//
//  Created by Jiang on 2018/3/23.
//  Copyright © 2018年 Jiang. All rights reserved.
//

#import <Foundation/Foundation.h>
@protocol HTTPPlugins <NSObject>

@end

@protocol HTTPAuthCreator <HTTPPlugins>
- (NSDictionary *)authHeadersWithHeaderField:(NSDictionary *)headers;
- (NSDictionary *)authParamsWithParams:(NSDictionary *)params;
@end

@protocol HTTPRequestSerialization <HTTPPlugins>
@property(nonatomic, copy) NSDictionary *params;
@property(nonatomic, copy) NSString *method;
@property(nonatomic, copy) NSDictionary *headerFields;
@property(nonatomic, copy) NSString *contentType;
- (NSURLRequest *)serializeRequestWithAuth:(id <HTTPAuthCreator>)auth;
@end

@protocol HTTPResponseValid <HTTPPlugins>
- (BOOL)validResponse:(NSHTTPURLResponse *)response
                 data:(NSData *)data
                error:(NSError *)error
              handler:(void(^)(id data,NSError *error))handler;
@end

@protocol SFNPlugin <HTTPPlugins>
@required
@property (nonatomic, strong)id <SFNPlugin> next;
@property (nonatomic, strong, readonly) id <SFNPlugin> (^addNext)(id <SFNPlugin> plugin);
@property (nonatomic, copy)NSURLSessionTask *(^retryClosure)(void);
@optional
- (id)cachedDataForRequest:(NSURLRequest *)reqest;
- (void)willStart:(NSURLRequest *)request;
- (id)handleWithRequest:(NSURLRequest *)request Reponse:(NSHTTPURLResponse *)response data:(id)data error:(NSError **)error;
- (id)testDataForRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData *data, NSError *error))completionHandler;;
@end

@interface HTTPPlugin : NSObject <SFNPlugin>
@property (nonatomic, strong)id <SFNPlugin> next;
@property (nonatomic, strong, readonly) id <SFNPlugin> (^addNext)(id <SFNPlugin> plugin);
@property (nonatomic, copy)NSURLSessionTask *(^retryClosure)(void);
@end
